package com.easygo.controller;

import com.easygo.client.GoodsClient;
import com.easygo.common.PageUtils;
import com.easygo.pojo.Goods;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@Scope("prototype")
public class GoodsController {

    @Resource
    GoodsClient goodsClient;

    @RequestMapping("/search/{pageIndex}/{pageSize}")
    public String search(@RequestParam(value = "keywords",defaultValue = "") String keywords, @PathVariable("pageIndex") Integer pageIndex, @PathVariable("pageSize") Integer pageSize, Model model) {
        PageUtils<Goods> pageUtils = goodsClient.search(keywords, pageIndex, pageSize);
        model.addAttribute("pageUtils",pageUtils);
        model.addAttribute("keywords",keywords); //数据回显
        return "categoryList";
    }


}
